home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’96
/
MFWM
/
INIT.c
next >
Wrap
C/C++ Source or Header
|
1997-09-24
|
2KB
|
91 lines
/*
*
* INIT.c
*
* Rob Hagopian
* with Oleg Kiselyov
* Based on code by: Joe Zobkiw
*
*/
/* #include files */
#include "A4Stuff.h"
#include "SetupA4.h"
/* #defines */
#define kINITid 0
/* FrontWindow patch stuff */
typedef pascal WindowPtr (*FrontWinProc)(void);
FrontWinProc gOldFrontWinAddr;
pascal WindowPtr FrontWinPatch(void);
/* main */
void main(void)
{
long oldA4;
Handle h;
/* set up our A4 context for _this file_ */
oldA4 = SetCurrentA4();
RememberA4();
/* detach ourselves */
h = Get1Resource('INIT', kINITid);
if (h) DetachResource(h);
/* initialize the globals in _this file_ */
gOldFrontWinAddr = 0L;
gOldFrontWinAddr = (FrontWinProc)GetToolTrapAddress(_FrontWindow);
SetToolTrapAddress((UniversalProcPtr)FrontWinPatch, _FrontWindow);
/* restore the a4 world */
SetA4(oldA4);
}
// Starting from win, find a window whose structure ("content")
// region contain the point pt (in abs coordinates)
// Note! Make sure it supports b/w windows, too
static CWindowPeek which_window_mouse_is_in(Point pt, CWindowPeek win)
{
for(; win; win = win->nextWindow) {
// skip over empty or invisible windows
if( win->contRgn == nil || !win->visible ) continue;
if(PtInRgn(pt,win->strucRgn))
return PtInRgn(pt,win->contRgn) ? win : nil;
}
return nil;
}
pascal WindowPtr FrontWinPatch(void)
{
WindowPtr thewin;
char * the_a5=NULL;
/* use the global data in _this file_ */
const long oldA4 = SetUpA4();
thewin = gOldFrontWinAddr();
/* restore the a4 world */
RestoreA4(oldA4);
if( thewin == nil )
return nil;
if( ((CWindowPeek)thewin)->windowKind == dialogKind )
return thewin;
{
EventRecord the_event;
WindowPtr another_win;
OSEventAvail(0, &the_event);
another_win = (WindowPtr)which_window_mouse_is_in(the_event.where, (CWindowPeek)thewin);
return another_win ? another_win : thewin;
}
}